/*
 *  POJ1129: Channel Allocation
 *
 *  Note: Four Color Theorem
 */

/*-------- Includes --------*/
#include <iostream>
#include <cstring>

using namespace std;

/*-------- Types --------*/

/*-------- Global Variables --------*/

/*-------- Function Prototypes --------*/

/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    int reps[26];   // channel value of repeaters
    int nRep;       // number of repeaters
    int chan;       // channel value

    char maps[26][32];  // maps of repeater networks
    bool mark[26][28];  // mark matrix

    while (cin >> nRep && nRep) {
        for (int i = 0; i < nRep; i++) cin >> maps[i];

        // initialize
        chan = 0;

        for (int i = 0; i < nRep; i++) reps[i] = -1;

        memset(mark, 0, sizeof(mark));

        // deal with each map
        for (int i = 0; i < nRep; i++) {
            // build mark table
            int len = strlen(maps[i]);

            for (int j = 2; j < len; j++) {
                int k = maps[i][j] - 'A';

                if (reps[k] == -1) continue;

                mark[i][reps[k]] = true;
            }

            // traverse mark table
            int t = 0;
            for (; t < chan; t++) {
                if (!mark[i][t]) {
                    reps[i] = t;
                    break;
                }
            }

            if (t == chan) reps[i] = chan++;
        }

        if (chan == 1) cout << "1 channel needed." << endl;
        else           cout << chan << " channels needed." << endl;
    }

    return 0;
}

/*-------- Functions --------*/

